<?php
class menu{
	public function init($params=array()){
		$this->db=$this->yum->library($this->yum->vars('app','database'));
		$this->prefix=$this->yum->vars('app','prefix');
	}
    public function GMenu($params=array()){
    	if(!isset($params['select'])){
    		$params['select']=array('id','name','controller','method','parent');
    	}
    	return $this->db->select($this->prefix.'menu',$params);
    }
    public function Menutree($filter=array()){
		$view=$this->GMenu(array('where'=>array('locked ='=>0),'order'=>array('sequence'=>'DESC')));
		foreach($view as $key => $value){
			if(isset($filter[$value['controller']][$value['method']])){
					continue;
			}else if($value['method']===''){
				continue;
			}
			unset($view[$key]);
		}
		$tree=$this->yum->library('tree',array('rows'=>$view));
		$view=$tree->build(0);
		foreach($view as $key => $value){
			if(!isset($value['child'])){
				unset($view[$key]);
			}
		}
		return $view;
    }
}
?>